<?php

/**
 * 微信网页授权获取access_token、openid
 * @param  $code
 * @return mixed
 */
function get_oauth_access_token($code){
	$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx40a077fc5281ed72&secret=66d832530be06ff892f8c7beb3c22b91&code=$code&grant_type=authorization_code";
	$openid_str = file_get_contents($url);
	$openid_obj = json_decode($openid_str);
	return $openid_obj;
}

/**
 * 微信网页授权获取用户信息
 * @param unknown $access_token
 * @param unknown $openid
 * @return mixed
 */
function get_oauth_userinfo($access_token,$openid){
	$url = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_CN";
	$openid_str = file_get_contents($url);
	$openid_obj = json_decode($openid_str);
	return $openid_obj;
}

/**
 * 判断是否为微信客户端
 * @return boolean
 */
function is_weixin()
{
	if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
		return true;
	}
	return false;
}
